from flask import Blueprint, jsonify, request
from pydantic import ValidationError

from cfganalysis.ProgramAnalysis import generate_cfg
from utils.parseData import response_json

c_bp = Blueprint('c', __name__)



@c_bp.route('/analyze', methods=['POST'])
def analyze_cprogram():

    # 从请求中获取 JSON 数据
    try:
        data = request.json
        code = data.get("code", "")
        if not code:
            response_json(514, "代码不能为空")  # 返回验证错误
        cfg = generate_cfg(code)
        return response_json(200, "Success", cfg)
    except (ValidationError, TypeError) as e:
        return response_json(503, str(e))# 返回验证错误



